﻿Imports System
Imports System.ComponentModel
Imports System.Globalization
Imports System.Workflow.Activities.Rules

Namespace System.Workflow.Activities.Rules.Design
    Friend Class RuleSetDefinitionTypeConverter
        Inherits TypeConverter
        ' Methods
        Public Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
            Return ((destinationType Is GetType(String)) OrElse MyBase.CanConvertTo(context, destinationType))
        End Function

        Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object
            If (context Is Nothing) Then
                Throw New ArgumentNullException("context")
            End If
            Dim ruleSet As RuleSet = [TryCast](value,RuleSet)
            If ((destinationType Is GetType(String)) AndAlso (Not ruleSet Is Nothing)) Then
                Return DesignerHelpers.GetRuleSetPreview(ruleSet)
            End If
            Return MyBase.ConvertTo(context, culture, value, destinationType)
        End Function

    End Class
End Namespace

